package com.massfords.jaxb;

import java.util.Set;

import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JPackage;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.Outline;

/**
 * Creates a no-op implementation of the Visitor interface. After creating the class
 * a visit method is added for each of the beans that were generated.
 * 
 * @author markford
 */
public class CreateBaseVisitorClass extends CodeCreator {

    private JDefinedClass mVisitor;

    public CreateBaseVisitorClass(JDefinedClass aVisitor, Outline aOutline, JPackage aPackage) {
        super(aOutline, aPackage);
        mVisitor = aVisitor;
    }

    @Override
    protected void run(Set<ClassOutline> aClasses) {
        setOutput(getOutline().getClassFactory().createClass(getPackage(), "BaseVisitor", null));
        getOutput()._implements(mVisitor);
        for (ClassOutline classOutline : aClasses) {
            // add the method to the base vizzy
            getOutput().method(JMod.PUBLIC, void.class, "visit").param(classOutline.implClass, "aBean");
        }
    }
}
